WorkerScript.onMessage = function(message) {
    doSignup(message);
}

function doSignup(message) {
    Qt.include("FetcherLogin.js"); // can't work, check
    var username = message.username;
    var password = message.password;
    var xhr = new XMLHttpRequest;
    var url = message.g.serverAPI + "users?client_secret=" + message.g.clientSecret + "&client_id=" + message.g.clientId + "&redirect_url=www.whatser.com";
    xhr.open("POST", url);
    var JSONUser = {"user": {
        "name": username.substring(0, username.indexOf('@')),
        "email": username,
        "password": password
        }
    };
    var params = JSON.stringify(JSONUser);
    xhr.setRequestHeader("Content-type", "application/json");
    xhr.setRequestHeader("Content-length", params.length);
    xhr.setRequestHeader("Connection", "close");

    xhr.onreadystatechange = function() {
        try {
            if (xhr.readyState == XMLHttpRequest.DONE) {
                WorkerScript.sendMessage({ 'result': 'SUCCESS' });
            }
        } catch (err) {
            console.log(err)
            WorkerScript.sendMessage({ 'result': 'FAILURE' });
        }
    }
    xhr.send(params);
}
